package com.shg.admin.controller;

import com.shg.admin.service.UserService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

/**
 * @DESCRIPTION:
 * @USER: shg
 * @DATE: 2023/11/30 23:05
 */
@Controller
@RequestMapping(value = "/user")
public class UserController {

    private final UserService userService;


    public UserController(UserService userService) {
        this.userService = userService;
    }

    @GetMapping(value = "/delete/{id}")
    public String deleteUserByUserId(@PathVariable(value = "id") Long userId,
                                     @RequestParam(value = "pn", defaultValue = "1") Integer pn,
                                     RedirectAttributes redirectAttributes) {
        userService.removeById(userId);
        redirectAttributes.addAttribute("pn", pn);
        return "redirect:/dynamic_table";

    }
}
